﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ValidationFramework.Web.MVC;
using ValidationFramework.Specifications;

namespace ValidationFramework.Validators.Web.MVC.JQuery.ScriptProviders
{
	public class IsRequiredStringProvider : IClientFunctionCallProvider
	{
		// -- IClientFunctionCallProvider Members

		public ClientFunctionCall GetClientFunctionCall(ISpecification specification)
		{
			var requiredValidator = specification as IsRequiredStringSpec;
			if (requiredValidator == null)
				throw new NotSupportedException(
					String.Format("The supplied validator of type '{0}' cannot be converted with this provider: '{1}'", 
					specification.GetType().FullName, 
					this.GetType().FullName
					)
				);

			return new ClientFunctionCall()
			{
				FunctionName = "requiredStringEx",
				FunctionArgs = new object[] { 
					"hasInitialValue=" + requiredValidator.HasInitialValue, 
					"initialValue=" + requiredValidator.InitialValue,
					"trimWhiteSpace=" + requiredValidator.TrimWhiteSpace,
					"ignoreWhiteSpace=" + requiredValidator.IgnoreCase
				}
			};
			
		}
	}
}
